<template>
  <el-dialog
      :title="`第三方物流订单列表`"
      :visible.sync="dialogUUOrderVisible"
      width="70%"
      lock-scroll
    >
      <div class="d-f mb-10">
        <span>配送方式：</span>
        <el-checkbox-group v-model="checkDeliveryList">
          <el-checkbox label="1">达达配送</el-checkbox>
          <el-checkbox label="2">顺丰物流</el-checkbox>
        </el-checkbox-group>
      </div>
      <el-table
        v-loading="uuOrderTableLoading"
        ref="uuMultipleSelection"
        :data="multipleSelection"
        style="width: 100%"
      >
        <el-table-column type="selection" width="44"></el-table-column>
        <el-table-column prop="xmbzNo" label="后台单号"></el-table-column>
        <el-table-column prop="branchWarehouse" label="状态">
          <template slot-scope="scope">
            <div>{{ scope.row.statusInfo }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="branchWarehouse" label="仓库"></el-table-column>
        <el-table-column prop="delivery" label="配送备注">
          <template slot-scope="{ row }">
            <span class="c-red fz-16 fw-bold">{{ row.deliveryNotes }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="delivery" label="配送员"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button
          type="danger"
          @click="submitUuOrders"
          :disabled="submitUuOrderDisabled"
          >发布订单</el-button
        >
        <el-button type="primary" @click="dialogUUOrderVisible = false"
          >取消</el-button
        >
      </span>
    </el-dialog>
</template>

<script>
import { createOrder } from "@/api/sf-order";

export default {
  data() {
    return {
      multipleSelection: [],
      dialogUUOrderVisible: false,
      uuOrderTableLoading: false,
      submitUuOrderDisabled: false,
      checkDeliveryList: ['1', '2'],
    };
  },
  methods: {
    show(multipleSelection) {
      this.checkDeliveryList = ['1', '2']
      this.dialogUUOrderVisible = true
      this.multipleSelection = multipleSelection
    },
    //发布UU订单
    submitUuOrders() {
      const selectionOrders = this.$refs.uuMultipleSelection.selection
      if (selectionOrders.length === 0) {
        this.$message.warning("请选择至少一张订单");
        return;
      }
      if (this.checkDeliveryList.length === 0) {
        this.$message.warning("请选择至少一种配送方式");
        return;
      }
      let noPutInArr = selectionOrders.filter(item => item.status !== 6)
      if(noPutInArr.length) {
        let tipStr = noPutInArr.map(item => item.xmbzNo).join('、')
        this.$confirm(`订单入库后才可发布,订单号${tipStr}暂未入库，请等待入库`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })  
        return   
      }
      this.$confirm("确定发布选择的订单?", {
        confirmButtonText: "发布",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.submitUuOrderDisabled = true; //发布订单状态是否可以点击状态
        let query = {
          xmbzNos: selectionOrders.map(item => item.xmbzNo),
          logisticsTypes: this.checkDeliveryList
        };
        this.uuOrderTableLoading = true;
        createOrder(query)
          .then((res) => {
            if (res.data.code == 200) {
              this.$notify({
                title: "成功",
                message: "发布成功",
                type: "success",
                duration: 2000,
              });
              this.dialogUUOrderVisible = false;
              this.$emit('submit')
            }
          })
          .finally(() => {
            this.uuOrderTableLoading = false;
            this.submitUuOrderDisabled = false;
          });
      })
    },
  }
};
</script>
<style lang="scss" scoped>

</style>